package cn.myra.io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class DataInAndOut2 {

	public static void main(String[] args) {
		
		File file = new File("D:/demo/data.txt");
		DataInAndOut2 dataio = new DataInAndOut2();
		try {
			dataio.write(file);
			dataio.read(file);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println("发生异常"+e.getMessage());
			e.printStackTrace();
		}
		
	}
	
	public void write(File file) throws Exception {
		//节点流
		FileOutputStream fos = new FileOutputStream(file);
		//缓冲流
		BufferedOutputStream bos = new BufferedOutputStream(fos);
		//数据输出流
		DataOutputStream dos = new DataOutputStream(bos);
		
		//写入数据
		
		int i =010;//8禁止
		int n =  0x81;//16进制
		int m = 0b10011010;//2进制
		System.out.println(i+" "+n+ " "+ m + " ");
	
		
		dos.writeUTF(i+"");
		dos.writeUTF("邢明明");
		dos.writeUTF("102101");
		dos.writeUTF("男");
		dos.writeUTF("23");
		dos.writeUTF("1202221012");
		dos.writeUTF("天津市东丽区");
		dos.flush();
		dos.writeUTF("邢明明1");
		dos.writeUTF("102102");
		dos.writeUTF("男");
		dos.writeUTF("25");
		dos.writeUTF("1202221012");
		dos.writeUTF("天津市东丽区");
		dos.flush();
		dos.writeUTF("邢明明2");
		dos.writeUTF("102103");
		dos.writeUTF("男");
		dos.writeUTF("29");
		dos.writeUTF("1202221012");
		dos.writeUTF("天津市东丽区");
		dos.flush();
		
		
		System.out.println("写入完毕");
		if(dos!=null) {
			dos.close();
		}
		if(bos!=null) {
			bos.close();
		}
		if(fos!=null) {
			fos.close();
		}
	}
	
	public void read(File file) throws Exception {
		//节点流
				FileInputStream fis = new FileInputStream(file);
				//缓冲流
				BufferedInputStream bis = new BufferedInputStream(fis);
				//数据输出流
				DataInputStream dis = new DataInputStream(bis);
				
				System.out.println(dis.readUTF());
				System.out.println(dis.readUTF()+"\t"+dis.readUTF()+"\t"+dis.readUTF()+"\t"
									+dis.readUTF()+"\t"+dis.readUTF()+"\t"+dis.readUTF()+"\t");
				System.out.println(dis.readUTF()+"\t"+dis.readUTF()+"\t"+dis.readUTF()+"\t"
									+dis.readUTF()+"\t"+dis.readUTF()+"\t"+dis.readUTF()+"\t");
				System.out.println(dis.readUTF()+"\t"+dis.readUTF()+"\t"+dis.readUTF()+"\t"
									+dis.readUTF()+"\t"+dis.readUTF()+"\t"+dis.readUTF()+"\t");
				
//				
				System.out.println("读取完毕");
				
				if(dis!=null) {
					dis.close();
				}
				if(bis!=null) {
					bis.close();
				}
				if(fis!=null) {
					fis.close();
				}
				
				
				
				
	}

}
